#!/bin/bash

# refer to https://gitee.com/api/v5/oauth_doc#/list-item-2
token_file=./gitee_token.json
username="xiasenlin1@huawei.com"
password=""
client_id='b6a3dc710e0438e993d9c13b4b68011f3208179f8734f63ee735f68abd8b6027'
client_secret='c41fa6cf3bb87dc367a574eee366d84a29c54f09fa7a1196e35cff07c379f468'
# source ~/.gitee_secret
if [ -e $token_file ]; then
    chmod 600 $token_file
fi
echo "Refreshing ~/.gitee_token.json"
curl -s -X POST --data-urlencode "grant_type=password" --data-urlencode "username=$username" --data-urlencode "password=$password" --data-urlencode "client_id=$client_id" --data-urlencode "client_secret=$client_secret" --data-urlencode "scope=user_info projects pull_requests issues notes keys hook groups gists enterprises" https://gitee.com/oauth/token > $token_file
chmod 400 $token_file